package com.glc.gao.gavin.rxjavademo.operator;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.glc.gao.gavin.rxjavademo.R;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.functions.Consumer;

public class CreateActivity extends BaseActivity {


    @Override
    protected int getContextView() {
        return R.layout.activity_create;
    }

    @Override
    public int getDescribeText() {
        return R.string.describe_create;
    }

    public void executeCreate(View view) {
        Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> emitter) throws Exception {
                print("subscribe AAA");
                emitter.onNext("AAA");
                print("subscribe BBB");
                emitter.onNext("BBB");
                print("subscribe onComplete");
                emitter.onComplete();
                print("subscribe CCC");
                emitter.onNext("CCC");
            }
        }).subscribe(new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                print("accept " + s);
            }
        });
    }
}
